package com.czxy.service.impl;

import com.czxy.dao.SuggestDao;
import com.czxy.dao.UserDao;
import com.czxy.domain.Suggest;
import com.czxy.domain.User;
import com.czxy.service.SuggestService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/2/11
 */
@Service
public class SuggestServiceimpl implements SuggestService {

    @Resource
    private SuggestDao suggestDao;

    @Resource
    private UserDao userDao;


    @Override
    public void addSuggest(Suggest suggest) {
        User user = userDao.selectByPrimaryKey(Integer.parseInt(suggest.getSperson()));
        suggest.setSperson(user.getUname());
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        String format = simpleDateFormat.format(date);
        suggest.setStime(format);
        suggestDao.insert(suggest);
    }

    @Override
    public List<Suggest> findAllguest() {
        return suggestDao.selectAll();
    }

    @Override
    public void delBysid(Integer sid) {
        suggestDao.deleteByPrimaryKey(sid);
    }
}
